package ru.jkff.jalgebra.order;

import java.util.Comparator;

/**
 * User: jkff
 * Date: Aug 22, 2009
 * Time: 1:11:00 PM
 */
public abstract class Lattices {
    public static BoundedLattice<Boolean> BOOLEAN_AND_OR = new BoundedLattice<Boolean>() {
        public Boolean min()                               { return false;  } 
        public Boolean max()                               { return true;   }
        public Boolean sup(Boolean a, Boolean b)           { return a || b; }
        public Boolean inf(Boolean a, Boolean b)           { return a && b; }
        public boolean isLessOrEqual(Boolean a, Boolean b) { return a;      }
    };

    public static <T> Lattice<T> linearOrder(final Comparator<? super T> cmp) {
        return new Lattice<T>() {
            public T sup(T a, T b)                 { return cmp.compare(a,b)>0 ? a : b; }
            public T inf(T a, T b)                 { return cmp.compare(a,b)<0 ? a : b; }
            public boolean isLessOrEqual(T a, T b) { return cmp.compare(a,b)<=0;        }
            public boolean areEqual(T a, T b)      { return cmp.compare(a,b)==0;        }
        };
    }
}
